<template>
	<app-layout>
		<scroll-view scroll-y class="layout">
			<image class="i1" src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_03.png" mode="widthFix"></image>
			<view class="cart">
				<view class="poster">
					<view class="click" @click="showQr">
						点击码
						<image src="https://hj.qfxwl.com/web/statics/img/admin/click.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="cart1">
					<view class="cart11">
						<image class="i2" src="https://hj.qfxwl.com/web/statics/img/admin/index-1.png" mode="widthFix"></image>
						<image class="i3" src="https://hj.qfxwl.com/web/statics/img/admin/QR.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="cart2">
					<view class="cart21">
						<text>{{ share.name }}</text>
						<image src="https://hj.qfxwl.com/web/statics/img/admin/man.png" mode="widthFix"></image>
					</view>
					<!-- <view class="cart22">产品经理（信息技术部）</view> -->
				</view>
				<view class="cart3">
					<view class="cart31">
						{{ share.mobile }}
						<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_15.png" mode="widthFix"></image>
					</view>
					<view class="cart31">
						{{ share.email }}
						<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_18.png" mode="widthFix"></image>
					</view>
					<view class="cart31">
						{{ share.address }}
						<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_20.png" mode="widthFix"></image>
					</view>
				</view><strong></strong>
			</view>
			<view class="navTo">
				<view class="item" @click="call(share.mobile)">
					<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_25.png" mode="widthFix"></image>
					<text>打电话</text>
				</view>
				<view class="item" @click="copy(share.email)">
					<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_27.png" mode="widthFix"></image>
					<text>邮箱</text>
				</view>
				<view class="item" @click="copy(share.mobile)">
					<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_29.png" mode="widthFix"></image>
					<text>加微信</text>
				</view>
				<view class="item" @click="map">
					<image src="https://hj.qfxwl.com/web/statics/img/admin/809e5e543eca05fb73e78e5848477ff_31.png" mode="widthFix"></image>
					<text>去拜访</text>
				</view>
			</view>
			<view class="cartQr" v-if="show">
				<image :src="qr" mode="widthFix"></image>
				<button @click="saveImg">保存二维码</button>
				<text @click="show=false">x</text>
			</view>
		</scroll-view>
	</app-layout>
</template>

<script>
export default {
	data() {
		return {
			share: {},
			qr:'',
			show:false
		};
	},
	methods: {
		saveImg(){
			this.$utils.batchSave(this.qr, 'image').then(() => {
			    uni.showToast({title: '保存成功'});
			});
		},
		showQr(){
			this.$request({url:this.$api.default.qrcodeShare}).then(res=>{
				//console.log(res);
				if(res.code==0){
					this.qr=res.data.pic_url
					this.show=true
				}
			})
		},
		map(){
			uni.openLocation({
				latitude:Number(this.share.latitude),
				longitude:Number(this.share.longitude),
				complete:(res)=>{
					console.log(res);
				}
			})
		},
		sendCall() {
			plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, addressbook => {
				//console.info('获取通信录对象成功');
				// console.info(addressbook)
				plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, addressbook => {
					// 向通讯录中添加联系人
					var contact = addressbook.create();
					//console.info(that.shuju.length);
					
						contact.name = {
							givenName: this.share.name
						};
						contact.phoneNumbers = [
							{
								type: '手机',
								value: this.share.company_name,
								preferred: true
							}
						];

						contact.save(res4 => {
							console.log(res4);
						});

				});
			});
		},
		call(phoneNumber) {
			uni.makePhoneCall({
				phoneNumber, //电话号码
				success: function(e) {
					console.log(e);
				}
			});
		},
		copy(data) {
			uni.setClipboardData({
				data,
				success: () => {
					uni.showToast({
						title: '复制成功'
					});
				}
			});
		},
		getStatus() {
			let that = this;
			that.$request({
				url: that.$api.share.new_apply_status
			})
				.then(response => {
					that.first = true;

					if (response.code === 0) {
						that.share = response.data.share;
						that.$hideLoading();
						if (response.data.share == null) {
							uni.navigateTo({
								url: '/pages/share/index/index'
							});
						}
					} else {
						that.$hideLoading();
						uni.showModal({
							content: response.msg,
							showCancel: false
						});
					}
				})
				.catch(() => {
					that.$hideLoading();
					that.$event.on(that.$const.EVENT_USER_LOGIN).then(() => {
						that.$store.dispatch('user/info');
						that.getStatus();
					});
				});
		}
	},
	onLoad() {
		if (this.$user.isLogin()) {
			this.$store.dispatch('user/refreshInfo');
		}
		this.$showLoading({
			type: 'global',
			text: '加载中...'
		});
		this.getStatus();
	}
};
</script>

<style scoped lang="scss">
	.cartQr{
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		z-index: 9999;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		overflow: hidden;
		image{
			width: 80%;
		}
		button{
			margin-top: 20upx;
			background-color: #ff4544;
			color: #fff;
		}
		text{
			color: #fff;
			text-align: center;
			display: block;
			font-size: 2em;
			margin-top: 20upx;
		}
	}
.navTo {
	margin: 40upx 3%;
	display: flex;
	justify-content: space-between;

	.item {
		width: 15%;
		text-align: center;
		font-size: 0.8em;
		color: #999;

		image {
			width: 100%;
		}
	}
}

.layout {
	height: calc(100vh - 90px);
	background-color: #fff;
}

.i1 {
	margin: 0 3%;
	margin-top: 1% !important;
	width: 94%;
	border-radius: 30upx 30upx 0 0;
	box-shadow: 0px 0px 6px 0px #ccc;
	overflow: hidden;
}

.cart {
	margin: 20upx 3%;
	position: relative;
	box-sizing: border-box;
	background-color: #f6f6f6;
	height: 250px;
	box-shadow: 0px 0px 6px 0px #ccc;
	border-radius: 0 0 30upx 30upx;

	.poster {
		position: absolute;
		color: #fff;
		width: 0;
		height: 0;
		right: 0;
		top: 0;
		border-left-color: transparent !important;
		border-bottom-color: transparent !important;
		border: 35px solid #1b68f6;

		.click {
			position: absolute;
			top: -65upx;
			right: -65upx;
			font-size: 0.8em;
			width: 160upx;
			display: flex;
			flex-direction: column;
			align-items: flex-end;

			image {
				width: 50upx;
			}
		}
	}

	.cart1 {
		.cart11 {
			display: flex;
			align-items: center;
			padding: 0 0 0 40upx;
			justify-content: space-between;

			.i2 {
				width: 300upx;
			}

			.i3 {
				width: 130upx;
			}
		}
	}

	.cart2 {
		padding: 0 40upx;
		.cart21 {
			font-size: 1.3em;

			image {
				width: 60upx;
			}
		}

		.cart22 {
			font-size: 0.8em;
		}
	}

	.cart3 {
		padding: 0 40upx;
		margin-top: 80upx;
		text-align: right;

		.cart31 {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
			image {
				margin-left: 10upx;
				width: 40upx;
			}
		}
	}
}
</style>
